< previous page page_162 next page >

Page 162
Each type of variable has its own memory requirements and is designed to work efficiently with different types of information. Therefore, you cannot store a string like "Hello" in a variable that you declare as an integer.
Table 8.2 shows some of the standard variable types that are available in Visual Basic. The table also shows the range of values that the variable can hold and the amount of memory required. Variables with smaller memory requirements should be used wherever possible to conserve system resources.
Table 8.2 Variables Store Many Types of Information
TypeStoresMemory RequirementRange of Values
IntegerWhole numbersTwo bytes32,768 to +32,767
LongWhole numbersFour bytes(approximately) +/ 2 billion
SingleDecimal numbersFour bytes+/ 1E-45 to 3E38
DoubleDecimal numbersEight bytes+/ 5E-324 to 1.8E308
CurrencyNumbers with up to 15 digits left of the decimal and four digits right of the decimalEight bytes+/ 9E14
StringText informationOne byte per characterUp to 65,400 characters for fixed-length string and upto 2 billion characters for dynamic strings
ByteWhole numbersOne byte0 to 255
BooleanLogical valuesTwo bytesTrue or False
DateDate and time informationEight bytes1/1/100 to 12/31/9999
ObjectInstances of classes; OLE objectsFour bytesN/A
VariantAny of the preceding data types16 bytes + 1 byte per characterN/A

In addition to the preceding variable types, you also can create user-defined types to meet your needs. Consider the following code segment, which demonstrates the declaration and use of a user-defined type:
Private Type Point
         x As Integer
         y As Integer

 
< previous page page_162 next page >